package com.yihaodian.search.query.converter;

import org.apache.log4j.Logger;
import org.apache.lucene.search.Query;

import com.yihaodian.api.search.query.BooleanQuery;
import com.yihaodian.api.search.query.NumericRangeQuery;
import com.yihaodian.api.search.query.TermQuery;

/**
 * Convert to lucene query
 * @author zhouhang
 *
 */
public class QueryConverter {
	
	private static Logger log = Logger.getLogger(QueryConverter.class);
	
	public static Query convert(com.yihaodian.api.search.query.Query query) {
		if(query == null)
			return null;
		
		if(query instanceof TermQuery) {
			return TermQueryConverter.convert((TermQuery) query);
		} else if (query instanceof BooleanQuery) {
			return BooleanQueryConverter.convert((BooleanQuery)query);			
		} else if (query instanceof NumericRangeQuery) { 
			return NumericRangeQueryConverter.convert((NumericRangeQuery) query);
		}else {
			log.error("Unknown query: " + query);
			return null;
		}
		
	}
}
